package com.songcha.library_common.util

import android.app.ActivityManager
import android.content.Context
import android.content.Context.ACTIVITY_SERVICE
import com.songcha.library_common.LibraryCommon

class ProcessUtil {

    companion object{
        /**
         * 根据Pid得到进程名
         */
        @JvmStatic
        fun getAppNameByPID(context: Context,pid:Int):String {
            val manager =  context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
            for (processInfo in  manager.runningAppProcesses) {
                if (processInfo.pid == pid) {
                    return processInfo.processName;
                }
            }
            return "";
        }

        @JvmStatic
        fun exitProcess( ){
            System.exit(0)
            throw RuntimeException("System.exit returned normally, while it was supposed to halt JVM.")
            // val manager = LibraryCommon.getContext().getSystemService(ACTIVITY_SERVICE) as ActivityManager
            // manager.killBackgroundProcesses(PackageUtil.getPackageName(LibraryCommon.getContext()))

            // val pid = android.os.Process.myPid()
             //android.os.Process.killProcess(pid)


        }

    }

}